package com.wwp.wkb.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.ui.ToastUtil2;
import com.wwp.wkb.R;

/**
 * 自定义toast
 */
public class ToastActivity extends Activity implements View.OnClickListener {
    private Button btn_1;
    private Button btn_2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);
        initView();
    }

    private void initView() {
        btn_1 = findViewById(R.id.btn_1);
        btn_1.setOnClickListener(this);
        btn_2 = findViewById(R.id.btn_2);
        btn_2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_1: {
                testToast();
            }
            break;
            case R.id.btn_2: {
                testToast2();
            }
            break;
            default:
                break;
        }
    }

    private void testToast() {
        View view = LayoutInflater.from(this).inflate(R.layout.temp_toast_horizontal, null);
        ImageView iv_icon = view.findViewById(R.id.iv_icon);
        iv_icon.setImageResource(R.mipmap.icon_successful);
        TextView tv_msg = view.findViewById(R.id.tv_msg);
        tv_msg.setText("成功图标");
        ToastUtil2.showToast(this, view, Toast.LENGTH_SHORT, Gravity.TOP, 0, 0);
    }

    private void testToast2() {
        View view = LayoutInflater.from(this).inflate(R.layout.temp_toast_vertical, null);
        ImageView iv_icon = view.findViewById(R.id.iv_icon);
        iv_icon.setImageResource(R.mipmap.icon_error);
        TextView tv_msg = view.findViewById(R.id.tv_msg);
        tv_msg.setText("错误图标");
        ToastUtil2.showToast(this, view, Toast.LENGTH_SHORT, Gravity.CENTER, 0, 0);
    }
}
